<template>
  <div id="updateBuildingDialog">
    <el-dialog title="新增" :visible.sync="updateBuildingDialogVisible" width="300px" :before-close="close">
      <el-form :model="updatebuildingForm" ref="updatebuildingForm" label-width="75px" label-position="left" :rules="rules">
        <el-form-item label="楼栋名称">
          <el-input v-model="updatebuildingForm.name" placeholder="请输入楼栋名称" style="width: 180px"></el-input>
        </el-form-item>
        <el-form-item label="性别" label-width="75px">
          <el-select v-model="updatebuildingForm.gender" placeholder="请选择性别" disabled style="width: 180px">
            <el-option
              v-for="item in genderOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="updateBuilding">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import building from '../../api/dormitory/building'

  export default {
    name: 'updateBuildingDialog',
    props: ['updateBuildingDialogVisible', 'updatebuildingForm'],
    data() {
      return {
        genderOptions: [
          {
            label: '男孩',
            value: 0
          },
          {
            label: '女孩',
            value: 1
          }
        ],
        rules: {
          name: [
            {required: true, message: '请输入学生姓名', trigger: 'blur'},
            {min: 2, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
          ],
          number: [
            {required: true, message: '请输入学生学号', trigger: 'change'}
          ],
          gender: [
            {required: true, message: '请选择性别', trigger: 'change'}
          ],
          grade: [
            {required: true, message: '请选择班级', trigger: 'change'}
          ],
          dormitory: [
            {required: true, message: '请选择宿舍', trigger: 'change'}
          ]
        }
      }
    },
    created() {
    },
    methods: {
      /*更新楼栋*/
      updateBuilding() {
        this.$refs["updatebuildingForm"].validate(valid => {
          if (valid) {
            building.updBuilding(this.updatebuildingForm).then(() => {
              this.$message.success("修改成功")
              this.close()
              this.$parent.getBuilding()
            })
          } else {
            this.$message.error("请正确填写信息")
          }
        })
      },
      /*关闭dialog*/
      close() {
        this.$refs['updatebuildingForm'].resetFields()
        this.$parent.closeDialog()
      }
    }
  }
</script>

<style scoped>

</style>
